#include "AntTweakBarManager.h"
#include "DX11ErrorReport.h"
//#include "DX11InputManager.h"

AntTweakBarManager::AntTweakBarManager()
{
	m_inputDetected = false;
}

void AntTweakBarManager::Initialise(ID3D11Device*& pDevice, int winWidth, int winHeight)
{
	// initialises tweakbar
	if (!TwInit(TW_DIRECT3D11, pDevice))
	{
		std::string test = TwGetLastError();
		std::wstring test2(test.begin(), test.end());
		DX11ErrorMsg(test2.c_str(), L"AntTweakBar", MB_YESNO);
	}

	m_pBar = TwNewBar("Twix Bar");

	if (!TwDefine(" GLOBAL help='AntTweakBar has been Integrated with Directx11' "))
	{
		std::string test = TwGetLastError();
		std::wstring test2(test.begin(), test.end());
		DX11ErrorMsg(test2.c_str(), L"AntTweakBar", MB_YESNO);
	}
	// parameters for the area you want thhe anttweakbar to cover 
	// (top left == (0, 0) bot right = (winWidth, winHeight))
	if (!TwWindowSize(winWidth, winHeight))
	{
		std::string test = TwGetLastError();
		std::wstring test2(test.begin(), test.end());
		DX11ErrorMsg(test2.c_str(), L"AntTweakBar", MB_YESNO);
	}

	
	//static float myVar = 0;
	//TwAddVarRW(m_pBar, "NameOfMyVariable", TW_TYPE_FLOAT, &myVar, "min=0 max=3 group=lol keyincr=l keydecr=L");
}

void AntTweakBarManager::Draw()
{	
	if (!TwDraw())
	{
		std::string test = TwGetLastError();
		std::wstring test2(test.begin(), test.end());
		DX11ErrorMsg(test2.c_str(), L"AntTweakBar", MB_YESNO);	
	}
}

bool AntTweakBarManager::CheckInput(HWND& hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (TwEventWin(hWnd, message, wParam, lParam))
	{
		m_inputDetected = true;
	}
	else
	{
		m_inputDetected = false;
	}

	//if (TheDX11InputManager::Instance()->GetMouseState().rgbButtons[DIMOUSE_BUTTON0 & 0x80])
	{
		m_inputDetected = false;
	}

	return m_inputDetected;
}

void AntTweakBarManager::SetInputDetected(bool b)
{
	m_inputDetected = b;
}

bool AntTweakBarManager::AddRWVariable(const std::string& varName, TwType varType, 
	void* var, const std::string& params)
{
	if (!TwAddVarRW(m_pBar, varName.c_str(), varType, var, params.c_str()))
	{
		std::string test = TwGetLastError();
		std::wstring test2(test.begin(), test.end());
		DX11ErrorMsg(test2.c_str(), L"AntTweakBar", MB_YESNO);	
		return false;
	}
	return true;
}